package com.woyou.ui.activity;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;
import android.annotation.SuppressLint;
import android.text.TextUtils;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;
import com.citaq.ideliver.R;
import com.woyou.ui.api.IBackEventStrategy;
import com.woyou.utils.eventbus.EventInfoSetup;
import de.greenrobot.event.EventBus;

/**
 * 搞不定看教程
 * 
 * @author tanglc
 */
@EActivity(R.layout.fm_lookbook)
public class LocationLookBookActivity extends BaseActivity implements IBackEventStrategy {

	@ViewById
	WebView everyoneweb;// 退出
	@ViewById
	TextView head_title;// 头部标题

	@AfterViews
	public void init() {
		initView();
	}
	
	/**
	 * 初始化View
	 */
	private void initView() {
		head_title.setText("定位教程");
		// String url = "http://"+Constant.WEB_ADDRESS+"/words/words.php";
		String url = "file:///android_asset/tutorial/index.html";
		initWebView(url);
	}

	// 退出、APP问题、服务问题、推荐店铺、我要开店
	@Click({ R.id.myback })
	void OnClick(View view) {
		switch (view.getId()) {
		case R.id.myback:
			// 退出意见反馈界面
			backOperate();
			break;
			
		default:
			break;
		}
	}

	@SuppressLint("SetJavaScriptEnabled")
	private void initWebView(String url) {
		// 如果访问的页面中有Javascript，则webview必须设置支持Javascript
		everyoneweb.getSettings().setJavaScriptEnabled(true);
		everyoneweb.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
		// 触摸焦点起作用
		everyoneweb.requestFocus();
		// 取消滚动条
		everyoneweb.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
		// 设置WevView要显示的网页：
		everyoneweb.loadUrl(url);
		// 设置不可缩放
		everyoneweb.getSettings().setSupportZoom(false);
		everyoneweb.getSettings().setBuiltInZoomControls(false);

		everyoneweb.setWebViewClient(new MyWebViewClient());
		everyoneweb.setWebChromeClient(new WebChromeClient());
		everyoneweb.addJavascriptInterface(this, "ideliver");
	}

	class MyWebViewClient extends WebViewClient {
		@Override
		public boolean shouldOverrideUrlLoading(WebView view, String url) {
			if (!TextUtils.isEmpty(url)) {
				everyoneweb.loadUrl(url);
			}
			return true;
		}
	}

	@Override
	public boolean backOperate() {
		finish();
		EventBus.getDefault().post(new EventInfoSetup());
		return true;
	}
	

}
